﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MxTol.Managers.Helpers;
using System.Data;

namespace MxTol.Managers
{
    /// <summary>
    /// 财经法规案例分析选择题业务管理器
    /// </summary>
    public class FrAnalysisChoiceManager
    {
        /// <summary>
        /// 以Json分页格式返回所有案例分析选择题
        /// </summary>
        public static string GetAllChoice(int currentPage, int pageSize)
        {
            string json = string.Empty;

            try
            {
                string sql = "select * from Fr_Analysis_Choice order by add_time desc;";
                json = PaginationHelper.GetJsonBySql(currentPage, pageSize, sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return json;
        }

        /// <summary>
        /// 以Json分页格式返回所有案例分析选择题
        /// </summary>
        public static string GetAllChoice(int currentPage, int pageSize, string sql)
        {
            string json = string.Empty;

            try
            {
                json = PaginationHelper.GetJsonBySql(currentPage, pageSize, sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return json;
        }

        /// <summary>
        /// 根据案例描述资料ID主键获取分析选择题
        /// </summary>
        public static DataTable GetChoiceByDescripeID(string id)
        {
            DataTable table = null;

            try
            {
                string sql = @"select id,title,answer_a,answer_b,answer_c,answer_d,answer_key,analysis 
                               from Fr_Analysis_Choice 
                               where descripe_id = '{0}' 
                               order by add_time asc;";

                sql = string.Format(sql,id);

                DataSet set = SqlHelper.ExecuteDataSet(ManagerConfig.ConnectionString,sql);
                if (set != null && set.Tables.Count > 0)
                {
                    table = set.Tables[0];
                }
                return table;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
